<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Admin\Excel\Action;

use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\Tools\AbstractTool;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class TemplateDownload extends AbstractTool
{
    /**
     * @return string
     */
    protected $title = '下载模板';

    protected $path = [
        'point_template' => 'storage\download\车辆类型模板.xlsx',
    ];

    protected $name;

    /**
     * @param mixed $name
     * @return string[]
     */
    public function getPath($name = 'point_template')
    {
        $path = $this->path;
        return $name ? $path[$name] : $path;
    }

    /**
     * @param string[] $path
     */
    public function setPath(array $path): void
    {
        $this->path = $path;
    }

    /**
     * @return mixed
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param mixed $name
     */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * Handle the action request.
     *
     * @return Response
     */
    public function handle(Request $request)
    {
        $names = 'storage\download\车辆类型模板.xlsx';
        $url = env('APP_URL');
        return $this->response()->download("{$url}/{$names}");
    }

    /**
     * @return array|string|void
     */
    public function confirm()
    {
        // return ['Confirm?', 'contents'];
    }

    /**
     * @return string|void
     */
    protected function href()
    {
        // return admin_url('auth/users');
    }

    /**
     * @param null|Authenticatable|HasPermissions|Model $user
     */
    protected function authorize($user): bool
    {
        return true;
    }

    /**
     * @return array
     */
    protected function parameters()
    {
        return [
            'name' => $this->getName(),
        ];
    }
}
